<?php

namespace app\index\controller;

use think\Controller;
use think\Db;
use think\facade\Session;
use think\Request;

class Shopcart extends Controller
{

    public function index()
    {
        $a = Session::get("user");
        $aa=Db::query('select * from htgoods join shopcart ON htgoods.id = shopcart.s_id where u_id = ?',[$a['id']]);
        return $aa;
    }

    public function create($id)
    {
    }

    /**
     * 保存新建的资源
     *
     * @param  \think\Request  $request
     * @return \think\Response
     */
    public function save()
    {
        $user = new \app\index\model\Shopcart();
        try {
            $user->joinshop();
            return '添加成功';
        } catch (\Exception $e) {
            return ['status' => false, 'error' => $e->getMessage()];
        }
    }

    /**
     * 显示指定的资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function read($id)
    {
        $i = new \app\index\model\Shopcart();
        try {
            $i->fukuan($id);
            return ['status' => true,'结账成功'];
        } catch (\Exception $e) {
            return ['status' => false, 'error' => $e->getMessage()];
        }
    }
    public function edit($id)
    {
        //
    }

    /**
     * 保存更新的资源
     *
     * @param  \think\Request  $request
     * @param  int  $id
     * @return \think\Response
     */
    public function update()
    {
        $bb=new \app\index\model\Shopcart();
        $bb->xiu();
        return '操作成功';
    }

    /**
     * 删除指定资源
     *
     * @param  int  $id
     * @return \think\Response
     */
    public function delete($id)
    {
        \app\index\model\Shopcart::destroy($id);
        return '操作成功';
    }
}
